package de.vocabulary.client;

import java.util.List;

import org.gwt.advanced.client.datamodel.ComboBoxDataModel;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.ServiceDefTarget;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.TabPanel;
import com.google.gwt.user.client.ui.Widget;

import de.vocabulary.client.editor.AddVocabulary;
import de.vocabulary.client.editor.ComboBoxWidget;
import de.vocabulary.client.editor.VocableEditor.GetTranslationCallback;
import de.vocabulary.client.service.VocabularyServiceAsync;

public class OverallScreen extends Composite  {
	
	@UiField
	AddVocabulary enterVocabulary;

	@UiField
	TabPanel tabs;
	@UiField
	TabPanel vocTabs;
	
	@UiField
	ComboBoxWidget languages = new ComboBoxWidget();

	
	private ComboBoxDataModel languageModules;
	
	private VocabularyServiceAsync service;
	
	public OverallScreen() {
		initWidget(uiBinder.createAndBindUi(this));
		tabs.selectTab(0);
		vocTabs.selectTab(0);
		languageModules = new ComboBoxDataModel();
		languages.getComboBox().setModel(languageModules);
		//TODO edit languageModule 
	}
	
	public void onLoad(){
		service = VocabularyServiceProvider.getService();
		service.getLanguages(new GetLanguagesCallback());
		//TODO add new language module
		//TODO change language module

	}
	
	private class GetLanguagesCallback implements AsyncCallback<List<String>> {

		@Override
		public void onFailure(Throwable caught) {
			 Window.alert(caught.getMessage());
			
		}
		
		
		@Override
		public void onSuccess(List<String> languages) {
			languageModules.clear();
			for (String l: languages){
				languageModules.add(l,l);
			}
			languageModules.add("3", "add new");	
			languageModules.setSelectedId(LanguageModuleManager.getLanguageModuleManager().getLanguageModule().getName());
		}

	}

	private static OverallScreenUiBinder uiBinder = GWT
			.create(OverallScreenUiBinder.class);

	interface OverallScreenUiBinder extends UiBinder<Widget, OverallScreen> {
	}

	
}
